package com.sr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.data.*;

public class moreinfoCI extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		moreDataService mds = new moreDataService();
		String type = request.getParameter("type");
		
		if("goMoreUpdate".equals(type)){
			String name =request.getParameter("pName");
			System.out.println(name);
			srProject srp = mds.getProjectById(name);
			System.out.println(srp);
			request.getSession().setAttribute("updateMoreProject", srp);
			response.sendRedirect("/scientific/jsp/more/moreUpdate.jsp");
		}
		
		else if("moreUpdate".equals(type)){
			srProject srp = new srProject();
			srp.setprojectName(request.getParameter("name"));
			srp.setContract_Pic(request.getParameter("contract"));
			srp.setTotalMoney(Double.parseDouble(request.getParameter("TotalMoney")));
			srp.setRealEndDate(request.getParameter("RealEndDate"));
			srp.setCompletionTask(request.getParameter("completionTask"));
			srp.setPassAudit( request.getParameter("passAudit"));
			srp.setConclusionReport(request.getParameter("conclusionReport"));
			srp.setRank( request.getParameter("rank"));
			srp.setRankContent(request.getParameter("rankContent"));
			if(mds.UpdateProject(srp)){
				response.sendRedirect("/scientific/searchProject?type=allMoreInfo");				
			}else{
				response.sendRedirect("/scientific/jsp/more/moreUpdate.jsp");	
			}			
		}
		else if("deleteMore".equals(type)){
			String name = request.getParameter("pName");
			if(mds.DelProject(name)){
				response.sendRedirect("/scientific/searchProject?type=allMoreInfo");
			}
		}
		else if("goMoreDetail".equals(type)){
			String name = request.getParameter("pName");
			srProject srp = mds.getProjectById(name);
			System.out.println("srp="+srp);
			request.getSession().setAttribute("detailMoreInfo", srp);
			response.sendRedirect("/scientific/jsp/more/detailMore.jsp");
		}
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doGet(request, response);

		
	}

}